package com.breakfast.fun.ui.user.pay;

import com.breakfast.fun.data.entity.user.Result;
import com.breakfast.fun.data.entity.user.recharge.PayBean;
import com.breakfast.fun.data.entity.user.recharge.RechargeMoney;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.L;
import com.breakfast.fun.util.T;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yukai on 16/9/23.
 */

public class BFPayPresenter extends BFPayContract.Presenter {


    @Override
    public void onStart() {

    }

    @Override
    public void payForBalance(String orderNo) {
        Map<String, String> map = Api.getInstance().getBaseParams();
        map.put("action", "pay");
        map.put("orderNo", orderNo);

        showLoadingDialog(true);
        rxManager.add(model.getPayForBalanceModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<Result>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        T.show("获取数据失败");
                        hideLoadingDialog();
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(Result result) {
                        if (result.isSuccess()) {
                            view.showPaySuccess();
                        } else {
                            T.show(result.getMsg());
                        }
                        hideLoadingDialog();
                    }


                }));
    }


}
